;_____________________________________________________________________
;---------------------------------------------------------------------
;	File: PML_Updater
;---------------------------------------------------------------------
;	Group: Overview
;	
;		Checks for updates on the PM App Launcher update server. Determines
;		if a later version is available for any of the apps, then downloads
;		and runs the <PM App Launcher Update> file.
;
;	Group: Update Method
;
;		Checks the update server folder in specified intervals (default 1 minute)
;		for the update file <PM App Launcher Update.exe>. If the file is found, 
;		the version of the update file and the version of the PM Application Launcher.exe
;		file in the user's install folder are compared; if the user's version is older,
;		the update file is copied to the user's temp folder, then run.
;
;	Group: About
;
;		- *Written By:* 	Rameen Bakhtiary
;		- *Last Modified:* 	
;---------------------------------------------------------------------
 #NoEnv
 #SingleInstance, Force
 SetWorkingDir %A_ScriptDir%
 SendMode, Input
;_____________________________________________________________________
;---------------------------------------------------------------------




updateCheck:	
	;***************************************************
	; 			CHECK FOR UPDATE FILE ON SERVER
	;***************************************************
	If FileExist(updateServer "\" updateFileName){ 
		
		;==================================
		; AN UPDATE FILE FOUND ON SERVER...
		;==================================
	
	
		;_________________________
		; 	GET VERSION OF UPDATER
		;
		FileGetVersion, installerVer, %updateServer%\%updateFileName%
		
		;____________________________
		; 	GET USERS CURRENT VERSION
		;
		FileGetVersion, myVersion, % A_ScriptFullPath
		
		
		if (installerVer > myVersion){
		
		;==============================
		;	USER NEEDS UPDATE - BEGIN
		;==============================
			FileDelete, %A_Temp%\PMinstaller.exe
			sleep 100
			
			;______________________________
			; 	COPY UPDATER TO TEMP FOLDER
			;
			FileCopy, %updateServer%\%updateFileName%, %A_Temp%\PMinstaller.exe, 1
			sleep 100
			
			;____________________________
			; 	LOG THAT USER IS UPDATING
			;
			FormatTime, timeLog, %a_now%,yyyy-M-d h:mm:ss
			FileAppend, %timeLog%`t  %user%`t`tForced update version %InstallerVer%`n, %LOGFILE%
			sleep 100
			
			;_____________________________
			; 	RUN THE UPDATE FILE & EXIT
			;
			run, %a_temp%\PMinstaller.exe,,useerrorlevel
			If (ErrorLevel){
				msgbox, PM App launcher had an issue downloading or running the update file.`n`nUpdate aborted.
				return
			}
			sleep 200
			ExitApp
		}
	}
return


